/*
 * Copyright 2011-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

package me.ijleex.platform.system.admin.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

import me.ijleex.platform.framework.mybatis.mapper.MyBatisMapper;
import me.ijleex.platform.system.admin.entity.Admin;

/**
 * 数据层
 *
 * @author liym
 * @since 2019-03-14 11:03:53 By 'codegen'
 */
@Mapper
public interface AdminMapper extends MyBatisMapper<Admin> {

    /**
     * 查询
     *
     * @param admin 条件
     * @return 信息
     * @since 2019-05-17 15:36
     */
    default Admin getAdmin(Admin admin) {
        List<Admin> admins = this.selectList(admin);
        return admins == null || admins.isEmpty() ? null : admins.get(0);
    }

    /**
     * 根据登录名查询管理员
     *
     * @param loginId 登录名
     * @return 管理员
     * @since 2020-08-09 10:00
     */
    Admin selectByLoginId(String loginId);

    /**
     * 判断登录名是否存在
     *
     * @param loginId 登录名
     * @return true/false
     * @see #isLoginIdExists(String)
     */
    Boolean isLoginIdExists0(String loginId);

    /**
     * 判断登录名是否存在
     *
     * @param loginId 登录名
     * @return true/false
     * @see #isLoginIdExists0(String)
     * @since 2022-04-01 14:57
     */
    default boolean isLoginIdExists(String loginId) {
        Boolean exists = this.isLoginIdExists0(loginId);
        return exists != null && exists;
    }

}
